package com.test.design.material.materialdesign;

import android.graphics.Matrix;
import android.os.Bundle;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.SeekBar;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

/**
 * author:harisucici on 2018/7/31 10:30
 * email:harisucici@gmail.com
 * name:
 * todo:
 */
public class BearActivity extends AppCompatActivity {
    private ConstraintLayout bearImage;
    private SeekBar bearSeek;
    private Matrix matrix = new Matrix();
    private int duration = 5000;
    private Interpolator interpolator = new DecelerateInterpolator();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bear);
        bearImage = (ConstraintLayout)findViewById(R.id.bear);




//        MyYAnimation myYAnimation = new MyYAnimation();
//        myYAnimation.setRepeatCount(Animation.RESTART); //旋转的次数（无数次）
//        bearImage.startAnimation(myYAnimation);

//        RotateAnimation rotate;
//        rotate =new RotateAnimation(-90f,90f,Animation.RELATIVE_TO_SELF,
//                0f,Animation.RELATIVE_TO_SELF,0f);
//        rotate.setDuration(1000);
//        rotate.setFillAfter(true);
//        bearImage.startAnimation(rotate);

    }

    //添加窗体在视图初始化完成过后
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            //开启动画
            int width = bearImage.getWidth()/2;
            int height = bearImage.getHeight()/2;
            bearImage.setPivotX(width);
            bearImage.setPivotY(height);
            
            bearImage.setRotationY(-45f);
            bearImage.animate().rotationY(45f).setDuration(duration).setStartDelay(300);
        }
    }
}
